-
-
Notifications
You must be signed in to change notification settings - Fork 362
doc(Modbus): add IModbusFactory documentation #6717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR integrates IModbusFactory into the project by updating menus, DI registration, sample code, and adding a new ModbusFactories documentation component with detailed usage instructions. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds IModbusFactory documentation to the BootstrapBlazor.Server project. The changes include new documentation pages, localization entries, menu navigation updates, and package dependencies for Modbus serial communication services.
- Creates comprehensive documentation for IModbusFactory service usage
- Adds localization support for both Chinese and English
- Reorganizes navigation structure to separate Socket and Modbus components
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/BootstrapBlazor.Server/Locales/zh-CN.json | Adds Chinese localization entries for Modbus components and updates Socket service descriptions |
| src/BootstrapBlazor.Server/Locales/en-US.json | Adds English localization entries for Modbus components and updates Socket service descriptions |
| src/BootstrapBlazor.Server/Extensions/ServiceCollectionSharedExtensions.cs | Removes ITcpSocketFactory service registration from shared extensions |
| src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs | Adds ITcpSocketFactory and IModbusFactory service registrations |
| src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs | Reorganizes menu structure to separate Socket and Modbus components with updated navigation |
| src/BootstrapBlazor.Server/Components/Samples/Sockets/SocketFactories.razor.cs | Updates namespace to match new directory structure |
| src/BootstrapBlazor.Server/Components/Samples/Sockets/SocketFactories.razor | Updates service registration method name |
| src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor.cs | Creates new component class for Modbus factory documentation |
| src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor | Creates comprehensive documentation page for IModbusFactory usage |
| src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj | Adds Longbow.Modbus package dependency |
| exclusion.dic | Adds spelling exclusions for Modbus-related terms |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点</li> | ||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SendAsync</code> 发送协议数据</li> | ||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>Close</code> 关闭连接</li> | ||
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SetDataHandler</code> 方法设置数据处理器</li> | ||
| <li>通过 <code>ITcpSocketClient</code> 实例属性 <code>ReceivedCallBack</code> 方法设置接收数据处理器(注意:此回调未做任何数据处理为原始数据)</li> |
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation incorrectly references ITcpSocketClient methods when describing IModbusClient usage. These should be updated to reference the appropriate Modbus client interface methods instead of TCP socket methods.
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点</li> | |
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SendAsync</code> 发送协议数据</li> | |
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>Close</code> 关闭连接</li> | |
| <li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SetDataHandler</code> 方法设置数据处理器</li> | |
| <li>通过 <code>ITcpSocketClient</code> 实例属性 <code>ReceivedCallBack</code> 方法设置接收数据处理器(注意:此回调未做任何数据处理为原始数据)</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点(如有需要)</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>ReadCoilsAsync</code> 或 <code>ReadRegistersAsync</code> 读取数据</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>WriteSingleCoilAsync</code> 或 <code>WriteSingleRegisterAsync</code> 写入数据</li> | |
| <li>通过 <code>IModbusClient</code> 实例方法 <code>Close</code> 关闭连接</li> | |
| <li>如需处理接收数据,可通过相关事件或回调方法进行设置(具体请参考 <code>IModbusClient</code> 的文档)</li> |
| private ITcpSocketFactory? TcpSocketFactory { get; set; } | ||
|
|
||
| private async Task CreateClient() | ||
| { | ||
| // 创建 ITcpSocketClient 实例 | ||
| var client = TcpSocketFactory.GetOrCreate("localhost", 0); | ||
|
|
||
| // 设置数据适配器 使用 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据 | ||
| var adapter = new DataPackageAdapter | ||
| { | ||
| DataPackageHandler = new FixLengthDataPackageHandler(4) | ||
| }; | ||
|
|
||
| // 如果 client 不销毁切记使用 RemoveDataPackageAdapter 移除回调委托防止内存泄露 | ||
| client.AddDataPackageAdapter(adapter, buffer => | ||
| { | ||
| // buffer 即是接收到的数据 | ||
| return ValueTask.CompletedTask; | ||
| }); | ||
|
|
||
| // 连接远端节点 连接成功后自动开始接收数据 |
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code example incorrectly shows using ITcpSocketFactory and ITcpSocketClient in Modbus documentation. This should demonstrate IModbusFactory and IModbusClient usage instead.
| private ITcpSocketFactory? TcpSocketFactory { get; set; } | |
| private async Task CreateClient() | |
| { | |
| // 创建 ITcpSocketClient 实例 | |
| var client = TcpSocketFactory.GetOrCreate("localhost", 0); | |
| // 设置数据适配器 使用 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据 | |
| var adapter = new DataPackageAdapter | |
| { | |
| DataPackageHandler = new FixLengthDataPackageHandler(4) | |
| }; | |
| // 如果 client 不销毁切记使用 RemoveDataPackageAdapter 移除回调委托防止内存泄露 | |
| client.AddDataPackageAdapter(adapter, buffer => | |
| { | |
| // buffer 即是接收到的数据 | |
| return ValueTask.CompletedTask; | |
| }); | |
| // 连接远端节点 连接成功后自动开始接收数据 | |
| private IModbusFactory? ModbusFactory { get; set; } | |
| private async Task CreateModbusClient() | |
| { | |
| // 创建 IModbusClient 实例 | |
| var client = ModbusFactory.GetOrCreateTcpMaster("modbus", options => | |
| { | |
| options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0); | |
| }); | |
| // 设置数据包处理器(如有需要,可自定义处理器) | |
| var handler = new FixLengthDataPackageHandler(4); | |
| client.SetDataHandler(handler, buffer => | |
| { | |
| // buffer 即是接收到的数据 | |
| return ValueTask.CompletedTask; | |
| }); | |
| // 连接远端 Modbus 设备 |
| }</Pre> | ||
|
|
||
| <p class="code-label">针对第三方程序集的数据类型解决方案如下:</p> | ||
| <p>使用 <code></code></p> |
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty code tags with no content. This appears to be incomplete documentation that should either be removed or completed with the intended content.
| <p>使用 <code></code></p> | |
| <p>使用</p> |
| <PackageReference Include="BootstrapBlazor.VideoPlayer" Version="9.0.3" /> | ||
| <PackageReference Include="BootstrapBlazor.WinBox" Version="9.0.7" /> | ||
| <PackageReference Include="Longbow.Logging" Version="9.0.1" /> | ||
| <PackageReference Include="Longbow.Modbus" Version="9.0.0-beta01" /> |
Copilot
AI
Sep 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a beta version (9.0.0-beta01) in production code may introduce instability. Consider using a stable release version if available.
| <PackageReference Include="Longbow.Modbus" Version="9.0.0-beta01" /> | |
| <PackageReference Include="Longbow.Modbus" Version="9.0.0" /> |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6717 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 739 739
Lines 31713 31713
Branches 4462 4462
=========================================
Hits 31713 31713
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The badge count for the Modbus menu is set to 2 but you only add one demo item—update AddBadge to 1 or add the missing item.
- If IModbusFactory should be available in all contexts, consider registering AddModbusFactory in ServiceCollectionSharedExtensions or centralizing service registration.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The badge count for the Modbus menu is set to 2 but you only add one demo item—update AddBadge to 1 or add the missing item.
- If IModbusFactory should be available in all contexts, consider registering AddModbusFactory in ServiceCollectionSharedExtensions or centralizing service registration.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Link issues
fixes #6716
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Introduce IModbusFactory support by registering the service, adding a dedicated documentation page, updating navigation menus, and refining sample components.
New Features:
Enhancements:
Documentation: